/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.sml.SEFM.BUS;

import java.util.Iterator;
import java.util.List;
import javax.persistence.RollbackException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.SystemException;
import vn.com.sml.SEFM.DAO.UserRolesDAO;
import vn.com.sml.SEFM.domain.UserRoles;
/**
 *
 * @author Tunp
 */
public class UserRolesBUS {
        
    public static Integer saveUserRoles(UserRoles userRoles) throws SecurityException, RollbackException, HeuristicRollbackException, HeuristicMixedException, IllegalStateException, SystemException {
        return UserRolesDAO.saveUserRole(userRoles);
    }
   
    public static List<UserRoles> listUserRoles() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException{
        return UserRolesDAO.listUserRoles();
    }

    public UserRoles getUserRolesById(int id) throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
        List<UserRoles> lstUR = UserRolesDAO.listUserRoles();
        if(lstUR.isEmpty())
            return null;
        for (Iterator<UserRoles> it = lstUR.iterator(); it.hasNext();) {
            UserRoles userRoles = it.next();
            if(userRoles.getRoleId() == id)
                return userRoles;
        }
        return null;
    }
}
